package com.s10.ecloud.web.action;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.s10.ecloud.web.Constants;
import com.s10.ecloud.web.model.DeviceGroup;
import com.s10.ecloud.web.model.DeviceType;
import com.s10.ecloud.web.model.User;
import com.s10.ecloud.web.service.IDeviceService;

public class UpdateDeviceGroupAction extends ActionSupport {
	@Resource
	private IDeviceService deviceService;

	@Action(value = "/toUpdateDeviceGroup", results = { @Result(name = "success", location = "/page/ind/editDeviceGroupPage.jsp") })
	public String toUpdateDeviceGroup() throws Exception {
		User currentUser = ((User) ActionContext.getContext().getSession()
				.get(Constants.SESSION_KEY_USER));

		this.setDeviceGroup(deviceService.getDeviceGroupByID(this.targetId));

		return this.SUCCESS;
	}

	@Action(value = "/updateDeviceGroup", results = { @Result(name = "success", location = "/page/ind/index.jsp") })
	public String updateDeviceModel() throws Exception {

		User currentUser = ((User) ActionContext.getContext().getSession()
				.get(Constants.SESSION_KEY_USER));

		String messgae = deviceService.updateDeviceGroup(this.getDeviceGroup());// 查询PageMode

		if (messgae != null) {
			this.addActionMessage(messgae);
		}

		return this.SUCCESS;
	}

	private String functionCode;
	private int targetId;

	/**
	 * @return the targetId
	 */
	public int getTargetId() {
		return targetId;
	}

	/**
	 * @param targetId
	 *            the targetId to set
	 */
	public void setTargetId(int targetId) {
		this.targetId = targetId;
	}

	private DeviceGroup deviceGroup;

	/**
	 * @return the deviceModel
	 */
	public DeviceGroup getDeviceGroup() {
		return deviceGroup;
	}

	/**
	 * @param deviceModel
	 *            the deviceModel to set
	 */
	public void setDeviceGroup(DeviceGroup deviceGroup) {
		this.deviceGroup = deviceGroup;
	}

	/**
	 * @return the functionCode
	 */
	public String getFunctionCode() {
		return functionCode;
	}

	/**
	 * @param functionCode
	 *            the functionCode to set
	 */
	public void setFunctionCode(String functionCode) {
		this.functionCode = functionCode;
	}

}
